package com.czy.owner.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.entity.CouponsCountModel;
import com.czy.owner.utils.TimeUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;


/**
 * Created by wangyang on 2017/4/14 0014.
 */

public class MyCouPonsAdapter extends RecyclerArrayAdapter<CouponsCountModel.ListBean> {
    private Context ctx;
    private String type;

    public MyCouPonsAdapter(Context context, String type) {
        super(context);
        this.ctx = context;
        this.type = type;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyCouponsViewHolder(parent, ctx, type);
    }

    class MyCouponsViewHolder extends BaseViewHolder<CouponsCountModel.ListBean> {
        private int grayColor = Color.parseColor("#A8A8A8");
        private int yellowColor = Color.parseColor("#FDCD54");
        private int themeColor = Color.parseColor("#09c0c7");
        private LinearLayout ll_bg;
        private TextView tv_conpons_type;
        private TextView tv_used_case;
        private TextView tv_used_data;
        private TextView tv_used_time;
        private TextView tv_used_money;
        private TextView tv_used_yuan;
        private ImageView img_coupon_status;
        private ImageView img_coupons_type;
        private TextView tv_describe;
        private LinearLayout ll_xuxian;
        private TextView tv_use_store;
        private Context ctx;
        private String type;


        public MyCouponsViewHolder(ViewGroup parent, Context ctx, String type) {
            super(parent, R.layout.item_my_coupons2);
            ll_bg = $(R.id.ll_bg);
            tv_conpons_type = $(R.id.tv_conpons_type);
            tv_used_case = $(R.id.tv_used_case);
            tv_used_data = $(R.id.tv_used_data);
            tv_used_time = $(R.id.tv_used_time);
            tv_used_money = $(R.id.tv_used_money);
            tv_used_yuan = $(R.id.tv_used_yuan);
            img_coupon_status = $(R.id.img_coupon_status);
            img_coupons_type = $(R.id.img_coupons_type);
            tv_describe = $(R.id.tv_mdescribe);
            ll_xuxian = $(R.id.ll_xuxian);
            tv_use_store = $(R.id.tv_use_store);
            this.ctx = ctx;
            this.type = type;
        }

        @Override
        public void setData(final CouponsCountModel.ListBean model) {
            if (!type.equals("可使用")) {
                ll_bg.setBackgroundResource(R.mipmap.coupons_gray_bg);
                ll_xuxian.setBackgroundResource(R.mipmap.coupons_xuxian_gray_bg);
                tv_use_store.setBackgroundResource(R.drawable.selector_user_store_disenable_coupons_bg);
                tv_use_store.setTextColor(grayColor);
              if(!TextUtils.isEmpty(model.getStoreName())){
                  tv_use_store.setText("限"+model.getStoreName()+"使用");
              }else {
                  tv_use_store.setText("限平台商城使用");
              }

                tv_conpons_type.setTextColor(grayColor);
                tv_used_case.setTextColor(grayColor);
                tv_used_data.setTextColor(grayColor);
                tv_used_time.setTextColor(grayColor);
                tv_used_money.setTextColor(grayColor);
                tv_used_yuan.setTextColor(grayColor);
                if(model.getUseType().equals("only")){
                    img_coupons_type.setImageResource(R.mipmap.bg_coupons_unusered_gray);
                }else if(model.getUseType().equals("all")){
                    img_coupons_type.setImageResource(R.mipmap.bg_coupons_common_gray);
                }else {
                    img_coupons_type.setVisibility(View.GONE);
                }
            }else {
                if(model.getStoreId()!=0){ //黄色门店
                    ll_bg.setBackgroundResource(R.mipmap.coupons_red_bg);
                    ll_xuxian.setBackgroundResource(R.mipmap.coupons_xuxian_red_bg);
                    tv_use_store.setBackgroundResource(R.drawable.selector_user_store_bg);
                    tv_use_store.setTextColor(yellowColor);
                    if(!TextUtils.isEmpty(model.getStoreName())){
                        tv_use_store.setText("限"+model.getStoreName()+"使用");
                    }else {
                        tv_use_store.setText("限平台商城使用");
                    }

                    tv_conpons_type.setTextColor(yellowColor);
                    tv_used_data.setTextColor(yellowColor);
                    tv_used_time.setTextColor(yellowColor);
                    tv_used_money.setTextColor(yellowColor);
                    tv_used_yuan.setTextColor(yellowColor);
                }else { // 0 系统
                    ll_bg.setBackgroundResource(R.mipmap.coupons_blue_bg);
                    ll_xuxian.setBackgroundResource(R.mipmap.coupons_xuxian_blue_bg);
                    tv_use_store.setBackgroundResource(R.drawable.selector_user_store_system_coupons_bg);
                    tv_use_store.setTextColor(themeColor);
                    if(!TextUtils.isEmpty(model.getStoreName())){
                        tv_use_store.setText("限"+model.getStoreName()+"使用");
                    }else {
                        tv_use_store.setText("限平台商城使用");
                    }
                    tv_conpons_type.setTextColor(themeColor);
                    tv_used_data.setTextColor(themeColor);
                    tv_used_time.setTextColor(themeColor);
                    tv_used_money.setTextColor(themeColor);
                    tv_used_yuan.setTextColor(themeColor);
                }


                if(model.getUseType().equals("only")){
                    img_coupons_type.setImageResource(R.mipmap.bg_coupons_unusered_red);
                }else if(model.getUseType().equals("all")){
                    img_coupons_type.setImageResource(R.mipmap.bg_coupons_common_yellow);
                }else {
                    img_coupons_type.setVisibility(View.GONE);
                }
            }
            if (type.equals("已过期")) {
                img_coupon_status.setVisibility(View.VISIBLE);
                img_coupon_status.setImageResource(R.mipmap.icon_coupon_overdu);
            } else if (type.equals("已使用")) {
                img_coupon_status.setVisibility(View.VISIBLE);
                img_coupon_status.setImageResource(R.mipmap.icon_coupon_userd);
            } else {
                img_coupon_status.setVisibility(View.GONE);
            }

            if(model.getUseGoodsType().equals("transfer")){
                tv_use_store.setVisibility(View.GONE);
            }else {
                tv_use_store.setVisibility(View.VISIBLE);
            }

            tv_describe.setText(model.getCgDescription()+"");
            tv_conpons_type.setText(model.getCouponsName());

            if(model.getMinimum()==0){
                tv_used_case.setText("无门槛");
            }else {
                tv_used_case.setText("满" + String.format("%.2f", model.getMinimum()) + "元使用");
            }
            tv_used_money.setText(String.format("%.2f", model.getDenomination()));

            long endTime = model.getEndTime();
            long startTime = model.getStartTime();
            if (endTime == 0) {
                tv_used_time.setText("永久有效");
            } else {
                tv_used_time.setText(TimeUtils.formatTimeDifference4(startTime)+"-"+TimeUtils.formatTimeDifference4(endTime));
            }
//            int validityType = model.getValidityType();
//            int fixTimeValue = model.getFixTimeValue();
//            long startTime = model.getStartTime();
//            long endTime = model.getEndTime();
//            if (validityType == 0) {
//                tv_used_time.setText("永久有效");
//            } else if (validityType == 1) {
//                tv_used_time.setText(fixTimeValue + "天有效");
//            } else if (validityType == 2) {
//                tv_used_time.setText(TimeUtils.formatTimeDifference4(startTime) + "-" + TimeUtils.formatTimeDifference4(endTime));
//            } else {
//                tv_used_time.setText("永久有效");
//            }

        }
    }
}
